// Замена ссылки на профиль
$(function() {
    function changeProfileLink() {
        const menuLinks = $('.gc-account-leftbar a, .gc-account-user-menu a, .gc-account-user-submenu a');
        let changed = false;
        menuLinks.each(function() {
            const $link = $(this);
            const href = $link.attr('href');
            if (href && href.includes('/user/my/profile')) {
                // новая ссылка ниже
                $link.attr('href', '/user/my/profile');
                changed = true;
            }
        });       
        return changed;
    }   
    if (!changeProfileLink()) {
        const observer = new MutationObserver(function() {
            if (changeProfileLink()) {
                observer.disconnect();
            }
        });
        observer.observe(document.body, {
            childList: true,
            subtree: true
        });
    }
});

//Замена ссылки на обращение в поддержку
(function() {
            'use strict';
            
            var url = window.location.href;
            var path = window.location.pathname;
            
            console.log('Early redirect check:', {url: url, path: path});
            
            if (url.indexOf('/talks/conversation') !== -1 || 
                path === '/talks/conversation' || 
                path === '/talks/conversation/' ||
                path.indexOf('/talks/conversation') === 0) {
                
                console.log('EARLY REDIRECT to Telegram');
                
                window.stop();
                
                window.location.replace('https://t.me/vasily_ti');
                
                document.location.href = 'https://t.me/vasily_ti';
                window.location.href = 'https://t.me/vasily_ti';
                
                var meta = document.createElement('meta');
                meta.httpEquiv = 'refresh';
                meta.content = '0;url=https://t.me/vasily_ti';
                document.head.appendChild(meta);
                
                throw new Error('Redirecting to Telegram');
            }
        })();